﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Tailoring
{
    public partial class InvoiceHistoryGrid : Form
    {
        SqlConnection conn = new SqlConnection("Server= localhost; database=tailoringmng; integrated Security=true");
        public InvoiceHistoryGrid()
        {
            InitializeComponent();
        }

         public void loadinvoice()
        {

            {
                try
                {
                    
                    SqlConnection conn = new SqlConnection("Server= localhost; database=tailoringmng; integrated Security=true");
                    SqlCommand cmd = new SqlCommand("loadinvoice", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataAdapter da = new SqlDataAdapter(cmd);

                    if (conn == null && conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    DataTable dt2 = new DataTable("myTable");
                    da.Fill(dt2);
                    //BindingSource bs = new BindingSource();
                    //bs.DataSource = dt;
                    invoicedg.DataSource = dt2.DefaultView;
                    //lbdone.Text = dgriddone.RowCount.ToString();
                    //label15.Text = "Total Records:";
                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                }
            }
        
        }
       public void delinvoice(string st)
        {

                try
                {
                    conn.Open();

                    SqlCommand sqlcmd = new SqlCommand("delInvoice", conn);
                    sqlcmd.CommandType = CommandType.StoredProcedure;
                    sqlcmd.Parameters.AddWithValue("@statuskey", st);

                    sqlcmd.ExecuteReader();


                    conn.Close();
                }

                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("An error occurred: {0}", ex.Message));
                }
                finally
                {
                    conn.Close();
                }
        }
        private void InvoiceHistoryGrid_Load(object sender, EventArgs e)
        {
            loadinvoice();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            delinvoice("Completed");
        }
    }
}
